package com.yiqi.liebang.feature.mine.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
import android.widget.EditText;

import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.liebang.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AddTopicPrizeActivity extends BaseActivity implements Toolbar.OnMenuItemClickListener {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.edt_topic_prize_original)
    EditText mEdtTopicPrizeOriginal;
    @BindView(R.id.edt_topic_prize_preferential)
    EditText mEdtTopicPrizePreferential;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_add_topic_prize;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        mToolbar.inflateMenu(R.menu.menu_save);
        initToolBar(mToolbar, "话题价格", true, true);
        mToolbar.setOnMenuItemClickListener(this);
    }

    @Override
    protected void initData() {
        Double mPrizePreferential = this.getIntent().getDoubleExtra("mPrizePreferential", 0.0);//优惠价格
        Double mPrizeOriginal = this.getIntent().getDoubleExtra("mPrizeOriginal", 0.0);//原价
        if (mPrizePreferential!=null&&mPrizePreferential>0){
            mEdtTopicPrizePreferential.setText(mPrizePreferential+"");
        }

        if (mPrizeOriginal!=null&&mPrizeOriginal>0){
            mEdtTopicPrizeOriginal.setText(mPrizeOriginal+"");
        }
    }


    @Override
    public boolean onMenuItemClick(MenuItem item) {
        if (item.getItemId() == R.id.action_next) {

            if (TextUtils.isEmpty(mEdtTopicPrizeOriginal.getText().toString().trim())) {
                showMsg("请输入话题价格");
                return true;
            }
            if (TextUtils.isEmpty(mEdtTopicPrizePreferential.getText().toString().trim())) {
                showMsg("请输入话题优惠价格");
                return true;
            }

            if (Double.valueOf(mEdtTopicPrizeOriginal.getText().toString().trim()) <= 0) {
                showMsg("请输入有效的话题价格！");
                return true;
            }
            if (Double.valueOf(mEdtTopicPrizePreferential.getText().toString().trim()) <= 0) {
                showMsg("请输入有效的优惠价格！");
                return true;
            }

            if (Double.valueOf(mEdtTopicPrizeOriginal.getText().toString().trim())
                    <= Double.valueOf(mEdtTopicPrizePreferential.getText().toString().trim())) {
                showMsg("优惠价格必须小于原始价格！");
                return true;
            }


            Intent intent1 = new Intent();
            intent1.putExtra("original_prize", Double.valueOf(mEdtTopicPrizeOriginal.getText().toString().trim()));
            intent1.putExtra("preferential_prize", Double.valueOf(mEdtTopicPrizePreferential.getText().toString().trim()));
            setResult(1, intent1);
            finish();
        }
        return false;
    }


}
